import React, { Component, Fragment } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import Admin from '_pages/Admin'
import Login from '_pages/Login'
import NotFound from '_pages/NotFound'
import { isLogin } from '_utils'

export default class App extends Component {
  render() {
    return (
      <Fragment>
        <Switch>
          <Route path="/admin" render={(RouterProps) => {
            if (isLogin()) {
              return (
                <Admin {...RouterProps}/>
              )
            } else {
              return (
                <Redirect to="/login" exact/>
              )
            }
          }}/>
          <Route path="/login" component={Login}/>
          <Route path="/404" component={NotFound}/>
          {/* 进入后台直接重定向到admin页 */}
          <Redirect to="/admin" from='/' exact/>
          {/* 其他页面直接重定向到404 */}
          <Redirect to="/404"/>
        </Switch>
      </Fragment>
    )
  }
}
